import * as rollup from "rollup";
import { join } from "path";

const sources = [
  { input: "./array/index.js", name: "array" },
  { input: "./dom/index.js", name: "dom" },
  { input: "./is/index.js", name: "is" },
  { input: "./miscs/miscs.js", name: "miscs" },
  { input: "./readable/index.js", name: "readable" },
  { input: "./string/index.js", name: "string" },
  { input: "./random.js", name: "random" },
  { input: "./tree.js", name: "tree" },
];

sources.forEach(async (src) => {
  const bundle = await rollup.rollup({
    input: join("src", src.input),
  });

  await bundle.write({
    file: join("modules/es", src.name + ".js"),
    format: "esm",
  });
  await bundle.write({
    file: join("modules", src.name + ".js"),
    format: "cjs",
  });

  if (bundle) {
    // closes the bundle
    await bundle.close();
  }
});
